<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>发布岗位</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<style>
    #area-picker {
        position: absolute;
    }
</style>

<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">岗位名</label>
        <div class="layui-input-block">
            <input type="text" name="jname" lay-verify="required" lay-reqtext="岗位名不能为空" placeholder="请输入岗位名" value="" class="layui-input">
            <tip>填写岗位的名称。</tip>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">岗位分类</label>
        <form class="layui-input-block" action="" name="jtId">
            <div class="layui-form-item" id="area-picker" >
                <div class="layui-input-inline" style="width: 200px;">
                    <select id="type" lay-filter="a" class="province-selector" >
                        <option value="">请选岗位类型</option>

                    </select>
                </div>
                <div class="layui-input-inline" style="width: 200px;">
                    <select id="type1" class="city-selector"  lay-filter="b">
                        <option value="">请选岗位类型</option>
                    </select>
                </div>
            </div>
        </form>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">薪资范围</label>
        <div class="layui-input-block">
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="minSalary" placeholder="￥" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 100px;">
                <input type="text" name="maxSalary" placeholder="￥" autocomplete="off" class="layui-input">
            </div>
        </div>
    </div>


    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">工作地址</label>
        <div class="layui-input-block">
            <input type="text" name="workAddress" lay-verify="required" lay-reqtext="工作地址不能为空" placeholder="请输入工作地址" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">招聘人数</label>
        <div class="layui-input-inline" style="width: 100px;">
            <input type="text" name="count" lay-verify="required" lay-reqtext="招聘人数不能为空" placeholder="招聘人数" value="" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">岗位描述</label>
        <div class="layui-input-block">
            <textarea name="description" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">招聘要求</label>
        <div class="layui-input-block">
            <textarea name="requirement" class="layui-textarea" placeholder="请输入备注信息"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="saveBtn">确认发布</button>
        </div>
    </div>
</div>
<script src="../../js/commons.js"></script>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="../../js/jquery-3.6.0.js"></script>
<script>

    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;



        function selectJobType(parentId,selectId){
            $.ajax({
                url:  URL + "recruiter/job/jobType",
                data: {parentId:parentId},
                success: function (result){
                    var $select = $("#" + selectId);
                    $select.empty();
                    if (result.code == 0){
                        $.each(result.data,function (index,ele){
                            $select.append("<option value='" + ele.jtid + "'>" + ele.jtname + "</option>")
                        })
                        form.render();//修改了表单中的数据需要重新渲染表格
                    }
                    if (selectId == "type"){
                        selectJobType($select.val(),"type1");
                    }
                }
            })

        }
        selectJobType(0,"type")

        form.on('select(a)', function(data){
            var $select = $("#" + data.elem.id);
                selectJobType($select.val(),"type1")
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.jtId=$("#type1").val()
            data.field // 需要提交的参数
            $.ajax({
                url : URL + "recruiter/job/publishJob",
                data: data.field,
                headers: {"token":localStorage.getItem("token")},
                type: "post",
                success: function (result){
                    layer.msg(result.msg)
                    if (result.code == 2){
                        window.location.href = "job.html";
                    } else if (result.code == 0){//发布成功
                        layer.msg(result.msg,function (){
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                            window.location.href = "job.html";
                        })
                    } else {
                        layer.msg(result.msg)
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>